package com.cheer.ba.view.activity;

import android.app.Activity;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

import com.cheer.ba.R;
import com.cheer.ba.constant.IntentCode;
import com.cheer.ba.constant.IntentKey;
import com.cheer.ba.model.BreakCardListModel;
import com.cheer.ba.model.ResultBreak;
import com.cheer.ba.utils.TextViewUtils;
import com.cheer.ba.view.base.BaseCommAty;
import com.cheer.ba.view.base.CommonAdapter;
import com.cheer.ba.view.base.ViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 展示车辆违章信息界面
 *
 * @author HQ
 *         created at 2017/4/1 0001 11:01
 */
public class WatchCarInfoAty extends BaseCommAty {

    //没有违章记录
    @BindView(R.id.id_watch_car_txt)
    TextView mErrorTxt;

    @BindView(R.id.id_watch_car_listv)
    ListView mListView;

    private CommonAdapter<BreakCardListModel> mCarAdp;
    private List<BreakCardListModel> mCarsList = new ArrayList<BreakCardListModel>();

    private ResultBreak mCarRules;

    public static void startWatchCarInfoAty(Activity mContext, ResultBreak rules) {
        Intent intent = new Intent(mContext, WatchCarInfoAty.class);
        intent.putExtra(IntentKey.General.KEY_MODEL, rules);
        mContext.startActivityForResult(intent, IntentCode.Break.BREAK_REQUEST_CODE);
    }

    @Override
    public View loadView(LayoutInflater inflater, View childView) {
        return super.loadView(inflater, inflater.inflate(R.layout.aty_watchcarinfo, null, false));
    }

    @Override
    public void initView() {
        mCarRules = (ResultBreak) getIntent().getSerializableExtra(IntentKey.General.KEY_MODEL);
        setTitleText(mCarRules.carNumber);
        mCarAdp = new CommonAdapter<BreakCardListModel>(aty, mCarsList, R.layout.adp_car_rules) {
            @Override
            public void convert(ViewHolder helper, BreakCardListModel item) {
                if (null != item) {
                    helper.setText(R.id.id_car_break_time_txt, item.time);
                    helper.setText(R.id.id_handle_person_txt, item.department);
                    helper.setText(R.id.id_car_break_reason_txt, item.reason);
                    helper.setText(R.id.id_car_break_address_txt, item.address);

                    TextViewUtils.setSpannableStyleColor("扣分 " + item.degree, 3, (3 + item.degree.length()), (TextView) helper.getViewById(R.id.id_remark_score_txt), R.color.color_main);
                    TextViewUtils.setSpannableStyleColor("罚款 " + item.money + "元", 3, (item.money.length() + 4), (TextView) helper.getViewById(R.id.id_car_break_price_txt), R.color.color_main);
                }
            }
        };
        mListView.setAdapter(mCarAdp);
    }

    @Override
    public void initData() {
        if (null != mCarRules) {
            List<BreakCardListModel> carsRules = mCarRules.getRecords();
            if (null != carsRules && !carsRules.isEmpty()) {
                mErrorTxt.setVisibility(View.GONE);
                mListView.setVisibility(View.VISIBLE);
                mCarsList.clear();
                mCarsList.addAll(carsRules);
                mCarAdp.notifyDataSetChanged();
            } else {
                dataStatus(4);
                mErrorTxt.setVisibility(View.VISIBLE);
                mListView.setVisibility(View.GONE);
            }
        }
    }

    @Override
    public void onBackPressed() {
        setResult(IntentCode.General.ATY_FINISH);
        super.onBackPressed();
    }
}
